home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ABUSESRC.ZIP / AbuseSrc / abuse / inc / stack.hpp < prev    next >
C/C++ Source or Header  |  1996-01-24  |  740b  |  39 lines

  1. #ifndef __STACK_HPP_
  2. #define __STACK_HPP_
  3. #ifndef NO_LIBS
  4. #include "jmalloc.hpp"
  5. #else
  6. #include "fakelib.hpp"
  7. #endif
  8.  
  9. #include <stdio.h>
  10. struct cons_cell;
  11.  
  12. template<class T> class grow_stack        // stack does not shrink
  13.   public :
  14.   T **sdata;
  15.   long son;
  16.  
  17.   grow_stack(int max_size) { sdata=(T **)jmalloc(max_size,"pointer stack");  son=0; }
  18.   void push(T *data) 
  19.   {
  20.     sdata[son]=data;
  21.     son++;
  22.   }
  23.    
  24.   T *pop(long total) 
  25.   { if (total>son) { lbreak("stack underflow\n"); exit(0); }
  26.     son-=total;
  27.     return sdata[son];
  28.   }
  29.   void clean_up() 
  30.   { 
  31.     if (son!=0) fprintf(stderr,"Warning cleaning up stack and not empty\n");
  32.     jfree(sdata); 
  33.     sdata=NULL;  son=0; 
  34.   }
  35. } ;
  36.  
  37. #endif
  38.